Use { 0, } for structure initialization rather than memset()
authorColin Walters <walters@verbum.org>
Sat, 17 Aug 2013 11:59:23 +0000 (07:59 -0400)
committerColin Walters <walters@verbum.org>
Sun, 18 Aug 2013 11:20:46 +0000 (07:20 -0400)
It's cleaner, safer, and I had a totally wrong idea stuck in my head
about why memset() should be used.

https://bugzilla.gnome.org/show_bug.cgi?id=705968

src/libostree/ostree-repo-prune.c
src/libostree/ostree-repo-pull.c
src/ostree/ot-admin-deploy.c
src/ostree/ot-builtin-checksum.c
src/ostree/ot-builtin-pull-local.c
src/ostree/ot-builtin-trivial-httpd.c

index 6492e6e889c918f8b14932a6d1c593f7b24e3304..a64b1c3ec0b17a6c9e00692c0a87e77331b762b9 100644 (file)
@@ -103,11 +103,9 @@ ostree_repo_prune (OstreeRepo        *repo,
   gs_unref_hashtable GHashTable *objects = NULL;
   gs_unref_hashtable GHashTable *all_refs = NULL;
   gs_free char *formatted_freed_size = NULL;
-  OtPruneData data;
+  OtPruneData data = { 0, };
   gboolean refs_only = flags & OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY;
 
-  memset (&data, 0, sizeof (data));
-
   data.repo = repo;
   data.reachable = ostree_repo_traverse_new_reachable ();
 
index 14adeca763487a11f1efc3347f4808cc02104892..f108e3c6f5a6445070f1953eb4feea1b8aa87e70 100644 (file)
@@ -364,12 +364,11 @@ fetch_uri (OtPullData  *pull_data,
   gboolean ret = FALSE;
   gs_free char *uri_string = NULL;
   gs_unref_object SoupRequest *request = NULL;
-  OstreeFetchUriData fetch_data;
+  OstreeFetchUriData fetch_data = { 0, };
 
   if (g_cancellable_set_error_if_cancelled (cancellable, error))
     return FALSE;
 
-  memset (&fetch_data, 0, sizeof (fetch_data));
   fetch_data.pull_data = pull_data;
 
   uri_string = soup_uri_to_string (uri, FALSE);
@@ -1184,7 +1183,7 @@ ostree_repo_pull (OstreeRepo               *self,
   gs_free char *branch_rev = NULL;
   gs_free char *remote_mode_str = NULL;
   GSource *queue_src = NULL;
-  OtPullData pull_data_real;
+  OtPullData pull_data_real = { 0, };
   OtPullData *pull_data = &pull_data_real;
   SoupURI *summary_uri = NULL;
   GKeyFile *config = NULL;
@@ -1194,8 +1193,6 @@ ostree_repo_pull (OstreeRepo               *self,
   guint64 start_time;
   guint64 end_time;
 
-  memset (pull_data, 0, sizeof (*pull_data));
-
   pull_data->async_error = error;
   pull_data->main_context = g_main_context_get_thread_default ();
   pull_data->loop = g_main_loop_new (pull_data->main_context, FALSE);
index 9bb6f4884424cf94c2170d79d7a98f832c546153..89d20eba7efc92e280c16ac6ccf1ce3599bd7073 100644 (file)
@@ -247,7 +247,7 @@ checkout_deployment_tree (GFile             *sysroot,
   gs_unref_object GFile *osdeploy_path = NULL;
   gs_unref_object GFile *deploy_target_path = NULL;
   gs_unref_object GFile *deploy_parent = NULL;
-  ProcessOneCheckoutData checkout_data;
+  ProcessOneCheckoutData checkout_data = { 0, };
 
   root = (OstreeRepoFile*)ostree_repo_file_new_root (repo, csum);
   if (!ostree_repo_file_ensure_resolved (root, error))
@@ -272,7 +272,6 @@ checkout_deployment_tree (GFile             *sysroot,
   g_print ("ostadmin: Creating deployment %s\n",
            gs_file_get_path_cached (deploy_target_path));
 
-  memset (&checkout_data, 0, sizeof (checkout_data));
   checkout_data.loop = g_main_loop_new (NULL, TRUE);
   checkout_data.error = error;
   
index 999bdd2556321930ec5f2c30e13e4f690ca09382..cb61932a9ce143c88dac3409c23c318011b987cb 100644 (file)
@@ -61,9 +61,7 @@ ostree_builtin_checksum (int argc, char **argv, GFile *repo_path_path, GCancella
   GOptionContext *context;
   gboolean ret = FALSE;
   gs_unref_object GFile *f = NULL;
-  AsyncChecksumData data;
-
-  memset (&data, 0, sizeof (data));
+  AsyncChecksumData data = { 0, };
 
   context = g_option_context_new ("FILENAME - Checksum a file or directory");
   g_option_context_add_main_entries (context, options, NULL);
index d98a3a748e9a2830e76b9ffec1738e855a7f768f..23319cf6b2ac6e894e9be1fc0561987c1fed5c24 100644 (file)
@@ -173,14 +173,12 @@ ostree_builtin_pull_local (int argc, char **argv, GFile *repo_path, GCancellable
   gs_unref_hashtable GHashTable *commits_to_clone = NULL;
   gs_unref_hashtable GHashTable *source_objects = NULL;
   gs_unref_hashtable GHashTable *objects_to_copy = NULL;
-  OtLocalCloneData datav;
+  OtLocalCloneData datav = { 0, };
   OtLocalCloneData *data = &datav;
 
   context = g_option_context_new ("SRC_REPO [REFS...] -  Copy data from SRC_REPO");
   g_option_context_add_main_entries (context, options, NULL);
 
-  memset (&datav, 0, sizeof (datav));
-
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
index f431eff9eb8e35833c6140e8bf36669eca5b2ecc..610e1969edfed4166d1034334d3eaaf76f7bcda8 100644 (file)
@@ -284,14 +284,12 @@ ostree_builtin_trivial_httpd (int argc, char **argv, GFile *repo_path, GCancella
   gboolean ret = FALSE;
   GOptionContext *context;
   const char *dirpath;
-  OtTrivialHttpd appstruct;
+  OtTrivialHttpd appstruct = { 0, };
   OtTrivialHttpd *app = &appstruct;
   gs_unref_object GFile *dir = NULL;
   gs_unref_object SoupServer *server = NULL;
   gs_unref_object GFileMonitor *dirmon = NULL;
 
-  memset (&appstruct, 0, sizeof (appstruct));
-
   context = g_option_context_new ("[DIR] - Simple webserver");
 
   g_option_context_add_main_entries (context, options, NULL);